<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div>
        <input type="checkbox"  id="master"/>全选<br>
		<input type="checkbox" />1<br>
		<input type="checkbox" />2<br>
		<input type="checkbox" />3<br>
		<input type="checkbox" />4<br>
    </div>
    <script>
        let node = document.querySelector("#master")
        let nodes = document.querySelectorAll("div input")
        node.onclick = function(){
            nodes.forEach(function(item,i){
                item.checked = node.checked
            })
        }
        for(let i =1;i<nodes.length;i++){
            nodes[i].onclick = function(){
                let flag = true
                for(let i =1;i<nodes.length;i++){
                    if(!nodes[i].checked){
                        flag = false
                    }
                }
                if(flag){
                    node.checked = true
                }else{
                    node.checked = false
                }
            }
        }
    </script>
</body>
</html>